/*
 * 
 * TODO, this code was copied from the iOS ApplicationWindow, 
 * however the transitions need to be modified for Android
 * 
 * 
 */
function ApplicationWindow() {
	//declare module dependencies
	var MasterView = require('ui/common/MasterView'),
		DetailView = require('ui/common/DetailView');
		ProcessView = require('ui/common/process/process');
		DefinitionView = require('ui/common/process/definition');
		InputView = require('ui/common/process/input');
		OutputView = require('ui/common/process/output');
		ToolView = require('ui/common/process/tools');
		GlossaryView = require('ui/common/process/glossary');
		QuizView = require('ui/common/process/quiz');


	//construct UI
	var masterView = MasterView(),
		detailView = DetailView();
		//processView = ProcessView();
		//definitionView = DefinitionView();
		//inputView = InputView();

	//create master view container
	var masterContainerWindow = Ti.UI.createWindow({
		title:'Time Management'
	});
	masterContainerWindow.add(masterView);

	//create detail view container
	var detailContainerWindow = Ti.UI.createWindow({
		title:'Process Details'
	});
	detailContainerWindow.add(detailView);

	var processContainerWindow = Ti.UI.createTab({
		title:'Process',
		window:masterContainerWindow
	});
	
	//processContainerWindow.add(processView);*/
	
	var definitionContainerWindow = Ti.UI.createWindow({
		title:'Process Detail',
		window:masterContainerWindow
	});
	
	//definitionContainerWindow.add(definitionView);
	
	
	//create iOS specific NavGroup UI
	//var navGroup = Ti.UI.iOS.createNavigationWindow({
		//window:masterContainerWindow
	//});
	
	var b = Titanium.UI.createButton({
		title:'About',
		width:200,
		height:40,
		bottom:20
	});
	
	masterContainerWindow.rightNavButton = b;


b.addEventListener('click', function(e){
var dialog = Ti.UI.createAlertDialog({
    message: 'Version 1.0.0.0 \n External sources: \n \n A Guide to the Project Management Body of Knowledge (PMBOK) 5th Edition by PMI \n http://www.pmi.org\n  \n \nContributors: \nAkon Offiong \nTyler Ringhoffer \nVernaldi Metayer \n \n Course: BU CS633 Spring 2014 \n Professor Kanabar \n Facilitator: Michael Boccafola',
    ok: 'OK',
    title: 'Time Management PMP App'
  }).show();
});

	//add behavior for master view
	masterView.addEventListener('processSelected', function(e) {
		//detailView.fireEvent('itemSelected',e);
		//processView.fireEvent('itemSelected', e);
		//navGroup.openWindow(detailContainerWindow);
		//processContainerWindow._source = e.name;
		//navGroup.openWindow(processContainerWindow);
		
		var processView = new ProcessView({
			detailTitle: e.name
		});
		
		processContainerWindow.open(processView);
		
		processView.addEventListener('functionSelected', function(e){
		
		var select = e.name;
		
		if(select === "Definition"){
			var functionView = new DefinitionView({
			detailTitle: e.name,
			knowledge: e.knowledge
			
		});
		
		}
		else if(select === "Input"){
			var functionView = new InputView({
detailTitle: e.name,
			knowledge: e.knowledge			
		});
		}
		else if(select ==="Output"){
			var functionView = new OutputView({
detailTitle: e.name,
			knowledge: e.knowledge			
		});
		}
		else if(select === "Tools and Techniques"){
			var functionView = new ToolView({
detailTitle: e.name,
			knowledge: e.knowledge			
		});
		}
		else if(select === "Glossary"){
			var functionView = new GlossaryView({
detailTitle: e.name,
			knowledge: e.knowledge			
		});
		}
		else{
			var functionView = new QuizView({
detailTitle: e.name,
			knowledge: e.knowledge			
		});
		}
			processContainerWindow.open(functionView);
		
	});
	
	
	});
	

	return navGroup;
	
};

module.exports = ApplicationWindow;


/*
Example JSON object
var processInputObject = {
	"planScheduleManagement" : ["plan","charter","factors","assets"],
	"defineActivities" : [],
	"sequenceActivites" : [],
	"estimateActivityResources" :[]
};

*/
